package cn.edu.scau.cmi.zhengweibo.client;

import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;


import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentComponent;
import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentComposite;
import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentLeaf;
import cn.edu.scau.cmi.zhengweibo.composite.safe.SafeLeaf;

public class ConsistentCompositeClient {
	public static void main(String[] args) {
		System.out.println("这是一致组合模式");
		ConsistentComposite root = new ConsistentComposite("学校");
		Scanner scanner = new Scanner(System.in);
		
		ConsistentComposite consistentComposite = root;
		ConsistentComposite consistentComposite2 = null;
		ConsistentComponent consistentComponent = null;
		String name = null;
		
		while(true) {
			System.out.println("当前组织："+consistentComposite.getName());
			System.out.println("1.添加组织");
			System.out.println("2.删除组织");
			System.out.println("3.添加个人");
			System.out.println("4.查找组织");
			System.out.println("5.修改组织名称");
			System.out.println("6.退出");
			int num = scanner.nextInt();
			switch(num) {
			case 1: 
				System.out.print("请输入组织名称:");
				name = scanner.next();
				consistentComposite2 = new ConsistentComposite(name);
				consistentComposite.add(consistentComposite2);
				consistentComposite = consistentComposite2;
				root.show("");
				break;
			case 2:
				System.out.print("请输入要删除的组织名称:");
				name = scanner.next();
				consistentComponent = root.find(name);
				if(consistentComponent!=null) {
					root.remove(consistentComponent);
				}
				root.show("");
				break;
			case 3:
				System.out.print("请输入个人名称:");
				name = scanner.next();
				consistentComposite.add(new ConsistentLeaf(name));
				root.show("");
				break;
			case 4:
				root.show("");
				break;
			case 5:
				System.out.print("请输入修改组织名称:");
				name = scanner.next();
				consistentComponent = root.find(name);
				System.out.print("请输入修改后的组织名称:");
				name = scanner.next();
				if(consistentComponent!=null) {
					consistentComponent.name = name;
				}
				root.show("");
				break;
			case 6:
				System.exit(1);
			default:
				break;
			}
		}
	}
}